<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/10
 * Time: 15:34
 */
namespace app\houtai\controller\user;
use app\houtai\controller\BaseController;
use think\Db;
use think\Process;

class BackpackController extends BaseController{
    /**
     * @basic : 用户背包
     * @return : page
     *
     */
    public function indexAction(){
        $order = [];
        $CHANNELS   = $this->GetAdminChannel();
          ////////////////////////////////////////////////////////////////////////////
        $Channel = $this->request->param('Channel/d', -1);
        if ($Channel > 0 && array_key_exists($Channel, $CHANNELS)) {
            $conds['b.Channel'][] = ['IN', array_keys($CHANNELS)];
            $conds['b.Channel'][] = ['EQ', $Channel];
        } else {
            $conds['b.Channel'] = ['IN', array_keys($CHANNELS)];
        }
        $orderMap = [
          'A' => 'ReocrdID',
          'B' => 'UserID',
          'C' => 'BackIndex',
          'D' => 'ItemNum',
          'E' => 'BeforNum',
          'F' => 'NowNum',
          'G' => 'CreateTime',
        ];
        $this->orderField = array_key_exists($this->orderField, $orderMap) ? $this->orderField : 'G';
        $order[$orderMap[$this->orderField]] = $this->orderDirection;
        $list =  table('RecordBackpack a','rydb.record')->field([
            'a.RecordID','a.UserID','a.BackIndex','c.Name','b.Accounts','b.Compellation','b.Sex','b.RegisterDate','b.RegisterIP','b.GameLogonCount','b.LastLogonDate','b.LastLogonIP','b.AccountsType','b.GameID','b.NickName','b.AccountImgUrl','a.ItemNum','a.BeforNum','a.NowNum','a.CreateTime','a.Describe'
        ])
        ->join('CYBasicDB.dbo.AccountsInfo b','b.UserID = a.UserID','LEFT')
        ->join('CYBasicDB.dbo.BackpackGift c','c.BackIndex=a.BackIndex','LEFT')
        ->where($conds)->order($order)->paginate();
       return $this->fetch('', [
            'list'    => $list,
            'Channel' => $Channel,
            'CHANNELS'  => $CHANNELS,
        ]);
    }
}